package cn.tedu.tmall.front.mall.dao.persist.repository.impl;

import cn.tedu.tmall.common.pojo.vo.PageData;
import cn.tedu.tmall.common.util.PageInfoToPageDataConverter;
import cn.tedu.tmall.front.mall.dao.persist.mapper.GoodsMapper;
import cn.tedu.tmall.front.mall.dao.persist.repository.IGoodsRepository;
import cn.tedu.tmall.front.mall.pojo.vo.GoodsListItemVO;
import cn.tedu.tmall.front.mall.pojo.vo.GoodsStandardVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Slf4j
public class GoodsRepository implements IGoodsRepository {
    @Autowired
    GoodsMapper mapper;
    @Override
    public PageData<GoodsListItemVO> listByRecommend(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<GoodsListItemVO> list= mapper.listByRecommend();
        return PageInfoToPageDataConverter.convert(PageInfo.of(list));
    }

    @Override
    public PageData<GoodsListItemVO> listByCategory(Long categoryId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<GoodsListItemVO> list= mapper.listByCategory(categoryId);
        return PageInfoToPageDataConverter.convert(PageInfo.of(list));
    }

    @Override
    public GoodsStandardVO getStandardById(Long id) {
        log.debug("开始执行根据id查询商品信息");
        return mapper.getStandardById(id);
    }

}
